﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLToolkit.Data;

namespace MvcVietAir.Models
{
    public class RepositoryAirlines
    {
        private DbManager db = new DbManager("MvcVietAirConnectionString");


        public List<Airline> GetAll()
        {
            using (db)
            {
                return db.SetSpCommand("Airline_All").ExecuteList<Airline>();
            }
        }

        public List<Airline> FindByName(string name)
        {
            using (db)
            {
                return db.SetSpCommand("Airline_FindByName", db.Parameter("@Name", name)).ExecuteList<Airline>();
            }
        }

        public Airline Single(string id)
        {
            using (db)
            {
                return db.SetSpCommand("Airline_Single", db.Parameter("@Id", id)).ExecuteObject<Airline>();
            }
        }

        public int Create(Airline air)
        {
            using (db)
            {
                return db.SetSpCommand("Airline_Create", db.CreateParameters(air)).ExecuteNonQuery();
            }
        }

        public int Edit(Airline air)
        {
            using (db)
            {
                return db.SetSpCommand("Airline_Edit", db.CreateParameters(air)).ExecuteNonQuery();
            }
        }
        public int Delete(string id)
        {
            using (db)
            {
                return db.SetSpCommand("Airline_Delete", db.Parameter("@Id", id)).ExecuteNonQuery();
            }
        }
    }
}